package cn.wzc.crystal.platform.i18n.impl;

import cn.wzc.crystal.platform.i18n.I18nProvider;
import lombok.RequiredArgsConstructor;
import org.springframework.lang.NonNull;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@RequiredArgsConstructor
public class CacheableI18nProvider implements I18nProvider {

	private final Map<String, String> cache = new ConcurrentHashMap<>();

	private final I18nProvider provider;

	@Override
	public String getMessage(@NonNull String code, String locale) {
		return cache.computeIfAbsent(code + ":" + locale, cacheKey -> provider.getMessage(code, locale));
	}
}
